﻿#region Opis pliku
//-----------------------------------------------------------------------------
// TextScreen.cs
// Autor: Jan Czarnowski
// 2.1.2013
//-----------------------------------------------------------------------------
#endregion

#region Using...

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Content;
using System;
using System.Text;
using System.Collections.Generic;

#endregion

namespace pogra
{
    class TextScreen : GameScreen
    {
        string text;
        Color color;
        TimeSpan timeRemaining = TimeSpan.FromSeconds(1);

        public TextScreen(string text, Color color)
        {
            this.text = text;
            this.color = color;
        }

        public override void Draw(GameTime gameTime)
        {
            //ScreenManager.GraphicsDevice.Clear(Color.Black);

            ExtendedSpriteBatch exSpriteBatch = ScreenManager.ExtendedSpriteBatch;
            exSpriteBatch.End();
            exSpriteBatch.Begin();

            Rectangle vr = ScreenManager.ViewRect;

            Vector2 txtPos;
            txtPos.X = (vr.Width - ScreenManager.Font.MeasureString(text).X) / 2;
            txtPos.Y = (vr.Height - ScreenManager.Font.MeasureString(text).Y) / 2;

            ScreenManager.ExtendedSpriteBatch.DrawString(ScreenManager.Font, text, new Vector2(txtPos.X, txtPos.Y), color);

            exSpriteBatch.End();

            RTSGame game = ((RTSGame)ScreenManager.Game);
            exSpriteBatch.Begin(SpriteSortMode.Deferred,
                                BlendState.AlphaBlend,
                                null,
                                null,
                                null,
                                null,
                               game.Camera.GetTransformation(game.GraphicsDevice));
            
        }

        public override void Update(GameTime gameTime)
        {
            timeRemaining -= gameTime.ElapsedGameTime;

            if (timeRemaining <= TimeSpan.Zero)
            {
                LoadingScreen.Load(ScreenManager, true, new MenuBackground(), new MainMenu());
            }
        }

        public override void Exit()
        {
            base.Exit();

            ((RTSGame)ScreenManager.Game).Camera.Reset();
        }

        public override void HandleInput(InputState input, bool otherScreenHasFocus, ref bool eventHandled)
        {
            otherScreenHasFocus = true;
            eventHandled = true;
        }
    }
}
